import traceback

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains

class Base:
    # 加载驱动
    def __init__(self,driver):
        self.driver = driver

    # 打开网址
    def open_url(self,url):
        self.driver.get(url)

    # 定位元素
    def find_element(self,loc,time_out=20,poll_frequency=0.5):
        try:
            WebDriverWait(self.driver,time_out,poll_frequency).until(EC.presence_of_element_located(loc))
            return self.driver.find_element(*loc)
        except Exception:
            traceback.format_exc()

    # 点击事件
    def click(self,loc):
        self.find_element(loc).click()

    # 输入事件
    def send_keys(self,loc,text):
        self.find_element(loc).send_keys(text)

    # 双击
    def double_click(self,loc):
        ActionChains(self.driver).double_click(self.find_element(loc)).perform()

    # 三击
    def triple_click(self,loc):
        ActionChains(self.driver).double_click(self.find_element(loc)).click().perform()





